const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');


module.exports = {
    entry: { //打包入口文件
        main: './src/script/main.js',
    },
    devtool: 'inline-source-map',
    devServer: {
        contentBase: './dist',
        //hot: true
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(['dist']),//清理dist目录下无用的打包文件
        new HtmlWebpackPlugin({
            template: './src/view/index.html',//模板文件路径
            filename: 'index.html', //指定打包输出后的html文件的文件名
            inject: 'body' //将打包后的js文件放在head标签里
        })
        //new webpack.NamedModulesPlugin(),
        //new webpack.HotModuleReplacementPlugin(),
        //new UglifyJSPlugin()
    ],
    output: { //输出
        path: path.resolve(__dirname, 'dist'), //打包后的文件路径(和配置文件同级的dist目录下)
        filename: 'js/[name].[chunkhash].js' //打包后的文件名(dist/js/xxx.js)
    }

};